package aerith.components;
import java.beans.PropertyEditorSupport;
import java.util.Calendar;
import java.util.Locale;

public class LocaleEditor extends PropertyEditorSupport
{

    public LocaleEditor()
    {
        locale = Locale.getDefault();
        locales = Calendar.getAvailableLocales();
        length = locales.length;
        localeStrings = new String[length];
    }

    public String[] getTags()
    {
        for(int i = 0; i < length; i++)
            localeStrings[i] = locales[i].getDisplayName();

        return localeStrings;
    }

    public void setAsText(String s)
        throws IllegalArgumentException
    {
        int i = 0;
        do
        {
            if(i >= length)
                break;
            if(s.equals(locales[i].getDisplayName()))
            {
                locale = locales[i];
                setValue(locale);
                break;
            }
            i++;
        } while(true);
    }

    public String getAsText()
    {
        return locale.getDisplayName();
    }

    private Locale locales[];
    private String localeStrings[];
    private Locale locale;
    private int length;
}
